<?php
/*
 * @Create By: Vscode
 * @Author: falcon
 * @Date: 2020-08-29 19:52:50
 * @ 扫描出入库记录到表里；并更新 虚拟仓库库存 暂时没用了。 无法实现
 */

namespace application\timer;

use application\model\PdoModel;
use application\depend\PhpRedis;

class StocksUpdate{

    public function run(){
        //获取缓存； 如果没有就不运行
        $data = PhpRedis::get('stocksUpdate');
        if(empty($data)) return;

        // 先录入记录
        $this->recordOperation($data);
        $this->summaryStocks($data);
        
    }

    public function recordOperation(&$data){
        $exportData = $data['data'];
        $operation = $data['operation'];
        $user = $data['user'];
        // 数据表参数
        $sqlData['warehouse'] = $exportData['warehouse'];
        $sqlData['sku'] = $exportData['sku'];
        $sqlData['amount'] = $exportData['amount'];
        $sqlData['shelf'] = $exportData['shelf'];
        $sqlData['remark'] = $exportData['remark'];
        $sqlData['create_time'] = date('Y-m-d H:i:s');
        $sqlData['operation'] = $operation;
        $sqlData['operator'] = $user;

        PdoModel::insertData('warehouse_iodetail',$sqlData,'导入数据记录！');

    }// func

    // 汇总2-9号仓库所有SKU库存数到1号仓库 ：product 表
    public function summaryStocks(&$data){
        $exportData = $data['data'];
        if(!empty($exportData)){
            foreach($exportData as $v){
                
            }
        }
    }
}//class